package com.max.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.max.base.BaseController;
import com.max.common.R;
import com.max.entity.MettingRoom;
import com.max.service.IMettingRoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@Api(tags = "会议室管理相关接口", value = "会议室管理相关接口")
@RequestMapping(value = "/mettingRoom")
@RestController
public class MettingRoomController extends BaseController {


    @Autowired
    private IMettingRoomService mettingRoomService;


    @ApiOperation("查询会议室列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public R<List<MettingRoom>> list(MettingRoom mettingRoom) {
        startPage();
        LambdaQueryWrapper<MettingRoom> eq = new LambdaQueryWrapper<MettingRoom>()
                .like(StringUtils.isNotBlank(mettingRoom.getRoomName()), MettingRoom::getRoomName, mettingRoom.getRoomName())
                .eq(StringUtils.isNotBlank(mettingRoom.getRoomNum()), MettingRoom::getRoomNum, mettingRoom.getRoomNum())
                .like(StringUtils.isNotBlank(mettingRoom.getRoomAddress()), MettingRoom::getRoomAddress, mettingRoom.getRoomAddress())
                .eq(!Objects.isNull(mettingRoom.getRoomState()), MettingRoom::getRoomState, mettingRoom.getRoomState());
        List<MettingRoom> list = mettingRoomService.list(eq);
        return R.ok(list);
    }


    @ApiOperation("添加会议室")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public R<?> addMettingRoom(@RequestBody MettingRoom mettingRoom) {
        boolean save = mettingRoomService.save(mettingRoom);
        return R.result(save);
    }

    @ApiOperation("根据会议室ID更新会议室")
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public R<?> updateMettingRoomById(@RequestBody MettingRoom mettingRoom) {
        boolean update = mettingRoomService.updateById(mettingRoom);
        return R.result(update);
    }

    @ApiOperation("根据会议室ID删除会议室")
    @RequestMapping(value = "/deleteById/{id}", method = RequestMethod.POST)
    public R<?> deleteMettingRoomById(@PathVariable("id") Long id) {
        boolean delete = mettingRoomService.removeById(id);
        return R.result(delete);
    }


}
